import Vue from 'vue'
import Vuex from 'vuex'
import {getHomecasual, getHomeNav, getRecommendShop, getSearchGoods, getShopList} from './api'
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    homecasual:[],
    homenav:[],
    shoplist:[],
    recommend:[],
    searchgoods:[],
  },
  mutations: {
    homeCasual(state,{homecasual}){
      state.homecasual = homecasual;
    },
    homeNav(state,{homenav}){
      state.homenav=homenav
    },
    ShopList(state,{shoplist}){
      state.shoplist=shoplist
    },
    RecommendShopList(state,{recommend}){
      state.recommend=recommend
    },
    SearchGoods(state,{searchgoods}){
      state.searchgoods=searchgoods
    }
  },
  actions: {
    async reqHomecasual({commit}){
      const result = await getHomecasual();
      commit("homeCasual",{homecasual:result.message.data})
    },
    async reqHomeNav({commit}){
      const result = await getHomeNav();
      commit('homeNav',{homenav:result.message.data});
    },
    async reqShopList({commit}){
      const result = await getShopList();
      commit('ShopList',{shoplist:result.message.goods_list});
    },
    async reqRecommendShopList({commit}){
      const result = await getRecommendShop();
      commit('RecommendShopList',{recommend:result.message.data})
    },
    async reqSearchGoods({commit}){
      const result =await getSearchGoods();
      commit('SearchGoods',{searchgoods:result.message.data})
    }
  }
})
